IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[or_MemaUserInsert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.or_MemaUserInsert
Go

CREATE  PROCEDURE  dbo.or_MemaUserInsert  
	 
	@UserTypeID		int,
	@FirstName		nvarchar(100),
	@LastName		nvarchar(100),
	@Email				nvarchar(30),
	@Password			nvarchar(30),
	@IsActive			bit

AS  
DECLARE 
   @TranCountAtEntry int, @DateTime datetime, @UserID int
  

BEGIN TRY

SELECT @TranCountAtEntry = @@TRANCOUNT
SELECT @DateTime  = getdate() 

IF @TranCountAtEntry  = 0 
BEGIN TRANSACTION 

INSERT INTO MeMaUser( 
	UserTypeID		,				
	FirstName			,
	LastName			,
	Email					,
	Password				,
	IsActive			,
    LastModDate         ,
    CreatedDate       
 )
 VALUES
 ( 
	@UserTypeID		,				
	LTRIM(RTRIM(@FirstName))		,
	LTRIM(RTRIM(@LastName))			,
	LTRIM(RTRIM(@Email))					,
	LTRIM(RTRIM(@Password))				,
	@IsActive			,
	@DateTime,
	@DateTime
	)

 
IF @@TRANCOUNT > @TranCountAtEntry
COMMIT TRANSACTION

END TRY
BEGIN CATCH
  
  IF @@TRANCOUNT > @TranCountAtEntry
  ROLLBACK TRANSACTION

  -- Raise an error with the details of the exception
  or_raiseerror 

END CATCH
  